package com.itheima.service.impl;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    /**
     * 新增检查项
     * @param checkItem
     */
    @Override
    public void add(CheckItem checkItem) {
        checkItemMapper.add(checkItem);
    }

    /**
     * 查询所有检查项
     * @return
     */
    @Override
    public List<CheckItem> findAll() {
        List<CheckItem> list = checkItemMapper.selectAll();
        return list;
    }

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        Integer start = (currentPage - 1) * pageSize;
        String queryString = queryPageBean.getQueryString();

        List<CheckItem> list =checkItemMapper.selectPage(start,pageSize,queryString);
        long total = checkItemMapper.selectTotal(queryPageBean);

        return new PageResult(total,list);
    }

    /**
     * 删除检查项
     * @param id
     */
    @Override
    public void delete(Integer id) {
        checkItemMapper.delete(id);
    }

    /**
     * 根据id查询检查项
     * @param id
     * @return
     */
    @Override
    public CheckItem findById(Integer id) {
        CheckItem checkItem = checkItemMapper.findById(id);
        return checkItem;
    }

    /**
     * 编辑检查项
     * @param checkItem
     */
    @Override
    public void update(CheckItem checkItem) {
        checkItemMapper.update(checkItem);
    }

    /**
     * 根据检查组id查询检查项id
     * @param id
     * @return
     */
    @Override
    public List<Integer> findCheckItemId(Integer id) {
        List<Integer> list = checkItemMapper.findCheckItemId(id);
        return list;
    }
}
